package com.stand.hardcode.controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.stand.hardcode.entity.StandUser;

@SuppressWarnings("serial")
public class AddItemToWishListServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) {
		//Retrieve user to add wishlist and item ID
		StandUser user = (StandUser) request.getSession().getAttribute("currentUser");
		long item_id = Long.parseLong(request.getParameter("itemId"));
		int quantity = Integer.parseInt(request.getParameter("quantity"));
		
		//add item to user's wishlist
		user.addItemToWishList(item_id, quantity);
		
		try {
			response.setHeader("Refresh", "3; URL=listitems");
			response.getOutputStream().println("Added item to " +user.getName() + "'s wishlist! ");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}
